package com.example.a313ldy.yuejian_17.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.a313ldy.yuejian_17.Activity.Contest_detail;
import com.example.a313ldy.yuejian_17.Bean.Contest;
import com.example.a313ldy.yuejian_17.Gloablecalss.Yuejian;
import com.example.a313ldy.yuejian_17.R;
import com.squareup.picasso.Picasso;

import java.util.List;


public class ContestAdapter extends  RecyclerView.Adapter< RecyclerView.ViewHolder> {
    private Context mContext;
    private List<Contest.RacelistEntity> mList;
    public LayoutInflater mLayoutInflater;

    public ContestAdapter(Context mContext, List<Contest.RacelistEntity> List) {
        this.mContext = mContext;
        this.mList = List;
        //mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_contestlist, parent, false);
        ViewHolder v = new ViewHolder(view);

        return v;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Contest.RacelistEntity Contest = (Contest.RacelistEntity) mList.get(position);
        if (null == Contest)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.con_name.setText(Contest.getGame_name());
        if(!Contest.getGame_pic().isEmpty()) {
            Picasso.with(mContext).load(Yuejian.IMG_URL+Contest.getGame_pic()).into(viewHolder.con_pic);
        }

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =new Intent(mContext, Contest_detail.class);
                String img = Yuejian.IMG_URL+Contest.getGame_pic();
                String con_name = Contest.getGame_name();
                String con_intro = Contest.getGame_intro();
                String time = "时间："+Contest.getGame_time();
                String address = "地址："+Contest.getGame_webaddress();
                intent.putExtra("img",img);
                intent.putExtra("con_name",con_name);
                intent.putExtra("con_intro",con_intro);
                intent.putExtra("time",time);
                intent.putExtra("address",address);
                mContext.startActivity(intent);
            }
        });


    }

    @Override
    public int getItemCount() {
        return mList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView con_name;
        ImageView con_pic;

        public ViewHolder(View itemView) {
            super(itemView);
            con_name = (TextView) itemView.findViewById(R.id.con_name);
            con_pic = (ImageView) itemView.findViewById(R.id.con_pic);

        }
    }
}
